﻿using System.Data.Entity;
using System.Web.Security;

namespace AugustaDevelopersGuild.Models
{
    public class GuildMeetings : DbContext
    {
        public GuildMeetings()
        {
            Database.SetInitializer(new GuildDatabaseInitializer());
        }

        public DbSet<Meeting> Meetings { get; set; }
        public DbSet<Rsvp> Rsvps { get; set; }
        public DbSet<Forum> Forums { get; set; }
        public DbSet<Post> Posts { get; set; }
    }

    public class GuildDatabaseInitializer : CreateDatabaseIfNotExists<GuildMeetings>
    {
        protected override void Seed(GuildMeetings context)
        {
            base.Seed(context);

            var user = Membership.GetUser("testuser");
            if (user == null)
            {
                Membership.CreateUser("testuser", "password", "contact@augustadevelopers.org");

                Roles.CreateRole("Admin");
                Roles.AddUsersToRole(new[] { "testuser" }, "Admin");
            }
        }
    }
}